﻿var ifDebug = false;


// var url = 'http://47.98.197.126:18088/';
// var url = " http://home.feixiangzhineng.com:24587/api/anonymous/datacollect/threeDimensional";
// var wsUrl = "ws://47.98.197.126:8088/ws";

// var infoWindUrl = "http://home.feixiangzhineng.com:24587/#/"


var buildObjectCodeMap = new Map();
var buildObjectNameMap = new Map();

var chartleft0 = null, chartleft1 = null, chartright0 = null;

var dianli_total_input = Number('0.0'),
	dianli_total_output = Number('0.0'),
	other_total_input = Number('0.0'),
	other_total_output = Number('0.0');


var _scrollamount = 30;
$(function () {
	// initData();


	initChartleft0();
	initChartleft1();
	initChartRight1();

	//一小时更新
	setInterval(() => {
		// initChartleft0();
		// initChartLeft1();
		// initChartRight1();

	}, 60 * 60 * 1000);

	$("#clock").html(new Date().formatTime());

	setInterval(() => {
		$("#clock").html(new Date().formatTime());
	}, 1000);





});

window.addEventListener("resize", function () {
	if (chartleft0) {
		chartleft0.resize();
	}
	if (chartleft1) {
		chartleft1.resize();
	}
	if (chartright0) {
		chartright0.resize();
	}
	// if (chartright1) {
	// 	chartright1.resize();
	// }

});



function initData() {
	if (buildObjectList) {
		buildObjectList.forEach(buildObject => {
			buildObjectCodeMap.set(buildObject.code, buildObject);
			buildObjectNameMap.set(buildObject.name, buildObject);
		});
	}
}


function showWindowPopup(buildObject) {

	var windowUrl = url + "#/" + buildObject.code;

	console.log(windowUrl);
}

function showWarn(text) {
	$("#warnInfo").show();
	$("#warnInfoText").html(text);
}
function closeWarn() {
	$("#warnInfo").hide();
	$("#warnInfoText").html("");
	// clearWarningData();

}


function initLeft0() {
	var config = {
		url: '/api/anonymous/datacollect/threeDimensional/electricitySituation?inouttype=消耗',
		type: "get",
		dataType: "json",
		xhrFields: {
			withCredentials: true
		},
		success: function (data) {
			if (data && data.rows) {
				var _datalist = data.rows;

				var datalist = _datalist;
				datalist.sort(function (a, b) {
					return b.sumpointvalue - a.sumpointvalue
				})

				initChartleft0(datalist);
				var arrNowWarn = [];
				datalist.forEach(data => {
					var organname = data.organname;
					var sumpointvalue = data.sumpointvalue;
					var dictionaries = data.dictionaries;

					var _sumpointvalue = Number(sumpointvalue);
					dianli_total_output += _sumpointvalue;

					let html = `<p class="bb" value="${dictionaries}">${organname}</p>
								<p>${sumpointvalue}</p>`
					arrNowWarn[arrNowWarn.length] = html;
				});

				$('#dianli_total_output').text(dianli_total_output.toFixed(2));

				let allHtml = ``;
				for (let index = arrNowWarn.length - 1; index >= 0; index--) {

					allHtml += `<li>${arrNowWarn[index]}</li>`;
				}
				var titleHtml = `<li><p>名称</p><p>消耗量</p></li>`;

				$("#nowWarn-ul-left0").html(titleHtml + allHtml);

				// $('#nowWarn-div-left0').liMarquee({
				// 	direction: 'up',
				// 	scrollamount: _scrollamount
				// });

			} else {
				// $.modal.msgError("地图文件错误");
			}
		}
	};
	$.ajax(config)



}
function initChartleft0(datalist) {
	// console.log(datalist);
	var xData = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri'],
		yData = [10, 20, 30, 20, 10, 15];

	// datalist.forEach(data => {
	// 	var organname = data.organname;
	// 	var sumpointvalue = data.sumpointvalue;
	// 	var dictionaries = data.dictionaries;
	// 	xData[xData.length] = organname;
	// 	yData[yData.length] = sumpointvalue;
	// });

	// xData = xData.slice(0, 6);
	// yData = yData.slice(0, 6);
	let option = {
		tooltip: {
			show: true,

		},
		xAxis: [{
			type: 'category',
			// name:'车间名称',
			data: xData,
			show: false,
			axisLabel: {
				rotate: 38,
				show: false,
				textStyle: {
					fontFamily: 'Microsoft YaHei',
					fontSize: 15,
					color: '#fff'
				}
			}
		}
		],
		yAxis: {
			type: 'value',
			show: false,
			axisLabel: {
				show: false,
				textStyle: {
					fontFamily: 'Microsoft YaHei',
					fontSize: 10,
					color: '#0e94eb'
				}
			}
		},
		series: [
			{
				type: 'pie',
				// color: '#316bf3',
				data: yData,
				markPoint: {
					data: [
						{ type: 'max', name: 'Max' },
						// { type: 'min', name: 'Min' }
					]
				},
				// markLine: {
				// 	// data: [{ type: 'average', name: 'Avg' }]
				// },
				// emphasis: {
				// 	label: {
				// 		show: true,
				// 		fontSize: 15,
				// 		fontWeight: 'bold'
				// 	}
				// },
				itemStyle: {
					// barBorderRadius: 5,
					// borderWidth: 1,
					// borderType: 'solid',
					// borderColor: '#73c0de',
					// shadowColor: '#5470c6',
					// shadowBlur: 3
				}
			}
		]
	};

	if (chartleft0 != null) {
		chartleft0.dispose();
	}
	chartleft0 = echarts.init(document.getElementById("chartleft0"));
	chartleft0.setOption(option);
	chartleft0.resize();
}


function initLeft1() {
	// 
	var config = {
		url: '/api/anonymous/datacollect/threeDimensional/electricitySituation?inouttype=产出',
		type: "get",
		dataType: "json",
		xhrFields: {
			withCredentials: true
		},
		success: function (data) {
			if (data && data.rows) {
				var datalist = data.rows;

				datalist.sort(function (a, b) {
					return b.sumpointvalue - a.sumpointvalue
				})
				initChartleft1(datalist);
				var arrNowWarn = [];
				datalist.forEach(data => {
					var organname = data.organname;
					var sumpointvalue = data.sumpointvalue;
					var dictionaries = data.dictionaries;
					var _sumpointvalue = Number(sumpointvalue);
					dianli_total_input += _sumpointvalue;

					let html = `<p class="bb" value="${dictionaries}">${organname}</p>
						<p>${sumpointvalue}</p>`
					arrNowWarn[arrNowWarn.length] = html;

				});
				$('#dianli_total_input').text(dianli_total_input.toFixed(2));
				let allHtml = ``;

				for (let index = arrNowWarn.length - 1; index >= 0; index--) {
					allHtml += `<li>${arrNowWarn[index]}</li>`;
				}
				var titleHtml = `<li><p>名称</p><p>产出量</p></li>`;


				$("#nowWarn-ul-left1").html(titleHtml + allHtml);
				// $('#nowWarn-div-left1').liMarquee({
				// 	direction: 'up',
				// 	scrollamount: _scrollamount
				// });
			} else {
				// $.modal.msgError("地图文件错误");
			}
		}
	};
	$.ajax(config)

}

function initChartleft1(datalist) {

	// var xData = [], yData = [];
	// var _data = [
	// ];
	// datalist.forEach(data => {
	// 	var organname = data.organname;
	// 	var sumpointvalue = data.sumpointvalue;
	// 	// var dictionaries = data.dictionaries;
	// 	// xData[xData.length] = organname;
	// 	// yData[yData.length] = sumpointvalue;
	// 	_data.push({
	// 		value: sumpointvalue,
	// 		name: organname
	// 	})
	// });


	let option = {
		xAxis: {
			type: 'category',
			data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
		  },
		  yAxis: {
			type: 'value'
		  },
		  series: [
			{
			  data: [
				120,
				{
				  value: 200,
				  itemStyle: {
					color: '#a90000'
				  }
				},
				150,
				80,
				70,
				110,
				130
			  ],
			  type: 'bar'
			}
		  ]
	};

	if (chartleft1 != null) {
		chartleft1.dispose();
	}
	chartleft1 = echarts.init(document.getElementById("chartleft1"));
	chartleft1.setOption(option);
}


var otherData = new Map();



function initRight0Data() {
	// 
	var outputData;
	var inputData;

	// var otherData = new Map();

	var config = {
		url: '/api/anonymous/datacollect/threeDimensional/mediumSituation?inouttype=消耗',
		type: "get",
		dataType: "json",
		xhrFields: {
			withCredentials: true
		},
		success: function (data) {
			if (data && data.rows) {
				// var _datalist = data.rows;
				outputData = data.rows;

				outputData.sort(function (a, b) {
					return a.sumpointvalue - b.sumpointvalue
				})
				outputData.forEach(d => {
					var mediumname = d.mediumname;
					var outsumpointvalue = d.sumpointvalue;
					var dictionaries = d.dictionaries;

					otherData.set(mediumname, {
						'mediumname': mediumname,
						'outsumpointvalue': outsumpointvalue,
						'dictionaries': dictionaries,
						'insumpointvalue': 0
					})
				})


				$.ajax({
					url: '/api/anonymous/datacollect/threeDimensional/mediumSituation?inouttype=产出',
					type: "get",
					dataType: "json",
					xhrFields: {
						withCredentials: true
					},
					success: function (data) {
						if (data && data.rows) {
							inputData = data.rows;
							inputData.forEach(d => {
								var mediumname = d.mediumname;
								var insumpointvalue = d.sumpointvalue;
								var dictionaries = d.dictionaries;
								if (otherData.has(mediumname)) {
									otherData.get(mediumname)['insumpointvalue'] = insumpointvalue;
								} else {
									otherData.set(mediumname, {
										'mediumname': mediumname,
										'outsumpointvalue': 0,
										'dictionaries': dictionaries,
										'insumpointvalue': insumpointvalue
									})
								}
							})

							// console.log(otherData);
							initRight0Table(otherData);
							initChartRight0(otherData);

							// console.log(inputData);
						} else {
						}
					}
				})

			} else {

			}
		}
	};
	$.ajax(config)

}

function initRight0Table(otherData) {

	var arrNowWarn = [];
	otherData.forEach(data => {
		var mediumname = data.mediumname;
		var insumpointvalue = data.insumpointvalue;
		var outsumpointvalue = data.outsumpointvalue;
		var dictionaries = data.dictionaries;

		let html = `<p class="bb" value="${dictionaries}">${mediumname}</p>
						<p>${insumpointvalue}</p><p>${outsumpointvalue}</p>`
		arrNowWarn[arrNowWarn.length] = html;

	});
	let allHtml = ``;

	for (let index = arrNowWarn.length - 1; index >= 0; index--) {
		allHtml += `<li>${arrNowWarn[index]}</li>`;
	}
	var titleHtml = `<li><p>名称</p><p>产出量</p><p>消耗量</p></li>`;


	$("#nowWarn-ul-right0").html(titleHtml + allHtml);

}

function initChartRight0(otherData) {
	// var yData = [];

	// var xData_in = [], xData_out = [];
	// otherData.forEach(data => {
	// 	var mediumname = data.mediumname;
	// 	var insumpointvalue = data.insumpointvalue;
	// 	var outsumpointvalue = data.outsumpointvalue;
	// 	var dictionaries = data.dictionaries;
	// 	yData[yData.length] = mediumname;
	// 	xData_in[xData_in.length] = insumpointvalue;
	// 	xData_out[xData_out.length] = outsumpointvalue;
	// 	// yData[yData.length] = sumpointvalue;
	// });

	// xData = xData.slice(0, 6);
	// yData = yData.slice(0, 6);

	// var _data = [];

	// datalist.forEach(data => {
	// 	var mediumname = data.mediumname;
	// 	var sumpointvalue = data.sumpointvalue;
	// 	var dictionaries = data.dictionaries;


	// 	_data.push({
	// 		value: sumpointvalue,
	// 		name: mediumname
	// 	})
	// });

	let option = {
		tooltip: {
		  trigger: 'axis',
		  axisPointer: {
			// Use axis to trigger tooltip
			type: 'shadow' // 'shadow' as default; can also be 'line' or 'shadow'
		  }
		},
		legend: {},
		grid: {
		  left: '3%',
		  right: '4%',
		  bottom: '3%',
		  containLabel: true
		},
		xAxis: {
		  type: 'value'
		},
		yAxis: {
		  type: 'category',
		  data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
		},
		series: [
		  {
			name: 'Direct',
			type: 'bar',
			stack: 'total',
			label: {
			  show: true
			},
			emphasis: {
			  focus: 'series'
			},
			data: [320, 302, 301, 334, 390, 330, 320]
		  },
		  {
			name: 'Mail Ad',
			type: 'bar',
			stack: 'total',
			label: {
			  show: true
			},
			emphasis: {
			  focus: 'series'
			},
			data: [120, 132, 101, 134, 90, 230, 210]
		  },
		  {
			name: 'Affiliate Ad',
			type: 'bar',
			stack: 'total',
			label: {
			  show: true
			},
			emphasis: {
			  focus: 'series'
			},
			data: [220, 182, 191, 234, 290, 330, 310]
		  },
		  {
			name: 'Video Ad',
			type: 'bar',
			stack: 'total',
			label: {
			  show: true
			},
			emphasis: {
			  focus: 'series'
			},
			data: [150, 212, 201, 154, 190, 330, 410]
		  },
		  {
			name: 'Search Engine',
			type: 'bar',
			stack: 'total',
			label: {
			  show: true
			},
			emphasis: {
			  focus: 'series'
			},
			data: [820, 832, 901, 934, 1290, 1330, 1320]
		  }
		]
	  }

	if (chartright0 != null) {
		chartright0.dispose();
	}
	chartright0 = echarts.init(document.getElementById("chartright0"));
	chartright0.setOption(option);
}
function initRight1() {
	var config = {
		url: '/api/anonymous/datacollect/threeDimensional/mediumSituation?inouttype=产出',
		type: "get",
		dataType: "json",
		xhrFields: {
			withCredentials: true
		},
		success: function (data) {
			if (data && data.rows) {
				var _datalist = data.rows;

				var datalist = _datalist;
				datalist.sort(function (a, b) {
					return b.sumpointvalue - a.sumpointvalue
				})
				initChartRight1(datalist);

				var arrNowWarn = [];
				datalist.forEach(data => {

					var mediumname = data.mediumname;
					var sumpointvalue = data.sumpointvalue;
					var dictionaries = data.dictionaries;
					var _sumpointvalue = Number(sumpointvalue);
					other_total_input += _sumpointvalue;

					let html = `<p   value="${dictionaries}">${mediumname}</p>
						<p >${sumpointvalue}</p>`
					arrNowWarn[arrNowWarn.length] = html;

				});
				$('#other_total_input').text(other_total_input);
				let allHtml = ``;
				for (let index = arrNowWarn.length - 1; index >= 0; index--) {
					allHtml += `<li>${arrNowWarn[index]}</li>`;
				}
				$("#nowWarn-ul-right1").html(allHtml);

				// $('#nowWarn-div-right1').liMarquee({
				// 	direction: 'up',
				// 	scrollamount: _scrollamount
				// });

			} else {
				// $.modal.msgError("地图文件错误");
			}
		}
	};
	$.ajax(config)
}

function initChartRight1(datalist) {
	// var xData = [], yData = [];

	// datalist.forEach(data => {
	// 	var mediumname = data.mediumname;
	// 	var sumpointvalue = data.sumpointvalue;
	// 	var dictionaries = data.dictionaries;
	// 	xData[xData.length] = mediumname;
	// 	yData[yData.length] = sumpointvalue;
	// });

	// xData = xData.slice(0, 6);
	// yData = yData.slice(0, 6);

	 let option = {
		tooltip: {
		  trigger: 'axis',
		  axisPointer: {
			// Use axis to trigger tooltip
			type: 'shadow' // 'shadow' as default; can also be 'line' or 'shadow'
		  }
		},
		legend: {},
		grid: {
		  left: '3%',
		  right: '4%',
		  bottom: '3%',
		  containLabel: true
		},
		xAxis: {
		  type: 'value'
		},
		yAxis: {
		  type: 'category',
		  data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
		},
		series: [
		  {
			name: 'Direct',
			type: 'bar',
			stack: 'total',
			label: {
			  show: true
			},
			emphasis: {
			  focus: 'series'
			},
			data: [320, 302, 301, 334, 390, 330, 320]
		  },
		  {
			name: 'Mail Ad',
			type: 'bar',
			stack: 'total',
			label: {
			  show: true
			},
			emphasis: {
			  focus: 'series'
			},
			data: [120, 132, 101, 134, 90, 230, 210]
		  },
		  {
			name: 'Affiliate Ad',
			type: 'bar',
			stack: 'total',
			label: {
			  show: true
			},
			emphasis: {
			  focus: 'series'
			},
			data: [220, 182, 191, 234, 290, 330, 310]
		  },
		  {
			name: 'Video Ad',
			type: 'bar',
			stack: 'total',
			label: {
			  show: true
			},
			emphasis: {
			  focus: 'series'
			},
			data: [150, 212, 201, 154, 190, 330, 410]
		  },
		  {
			name: 'Search Engine',
			type: 'bar',
			stack: 'total',
			label: {
			  show: true
			},
			emphasis: {
			  focus: 'series'
			},
			data: [820, 832, 901, 934, 1290, 1330, 1320]
		  }
		]
	  };

	if (chartright0 != null) {
		chartright0.dispose();
	}
	chartright0 = echarts.init(document.getElementById("chartright0"));
	chartright0.setOption(option);
}


function open1() {

}







//鼠标滑动到按钮，按钮内容变成白色
var imgName;
$('.title-box').children('button').hover(function () {
	imgName = $(this).children('img').attr('src').split('.png')[0];
	$(this).children('img').attr('src', imgName + '_on.png');
}, function () {
	$(this).children('img').attr('src', imgName + '.png');

});

$('#info-img-1').on("click", function () {
	// $('#infoshowSY').show(500);
	// layer.msg('hello');
	var loadstr = '<video width="100%" height="100%"  controls="controls" autobuffer="autobuffer"  autoplay="autoplay" loop="loop"><source src="../Image/QQ%e8%a7%86%e9%a2%9120190515112853.mp4" type="video/mp4"></source></video>'
            

	layer.open({
		type: 1,
		title: '播放视频',
		content: loadstr //这里content是一个普通的String
	});
})



$('#tabBtn-left-center').on('click', function () {
	var _this = $(this);
	// console.log(_this.innerHTML)
	if (_this.children('span').html() == '图表') {
		_this.children('span').html('表格');
		$('.left-center').children('.ranking-box').show().siblings('.chart-box').hide();
	} else {
		_this.children('span').html('图表');
		$('.left-center').children('.chart-box').show().siblings('.ranking-box').hide();
	}
})

$('#tabBtn-left-bottom').on('click', function () {
	var _this = $(this);
	if (_this.children('span').html() == '图表') {
		_this.children('span').html('表格');
		$('.left-bottom').children('.ranking-box').show().siblings('.chart-box').hide();

	} else {
		_this.children('span').html('图表');
		$('.left-bottom').children('.chart-box').show().siblings('.ranking-box').hide();

	}
})


$('#tabBtn-right-top').on('click', function () {
	var _this = $(this);
	var aa = _this.children('span').html();
	if (_this.children('span').html() == '图表') {
		_this.children('span').html('表格');
		$('.right-top').children('.ranking-box').show().siblings('.chart-box').hide();

	} else {
		_this.children('span').html('图表');
		$('.right-top').children('.chart-box').show().siblings('.ranking-box').hide();

	}
})

$('#tabBtn-right-bottom').on('click', function () {
	var _this = $(this);
	var aa = _this.children('span').html();
	// console.log(_this.innerHTML)
	if (_this.children('span').value() == '图表') {
		_this.children('span').value('表格');
		$('.right-bottom').children('.ranking-box').show().siblings('.chart-box').hide();

	} else {
		// _this.text('图表');
		_this.children('span').value('图表');

		$('.right-bottom').children('.chart-box').show().siblings('.ranking-box').hide();
		// if (_this.data('state') == 1) {
		//     $('.table1').eq(0).show().siblings('table').hide();
		// } else if (_this.data('state') == 2) {
		//     $('.table1').eq(1).show().siblings('table').hide();
		// }
	}
})


function tartarAjax(_url, _successFunction) {
	$.ajax({
		url: _url,
		data: "",
		type: "get",
		dataType: "json",
		xhrFields: {
			withCredentials: true
		},
		error: function (response) { },
		success: function (result) {
			if ($.isFunction(_successFunction)) {
				_successFunction(result);
			}
		}
	});
}




Date.prototype.formatTime = function () {
	let fmt = "yyyy-MM-dd HH:mm:ss";
	let o = {
		"M+": this.getMonth() + 1,
		"d+": this.getDate(),
		"H+": this.getHours(),
		"m+": this.getMinutes(),
		"s+": this.getSeconds()
	};
	let year = this.getFullYear();
	let yearstr = year + '';
	yearstr = yearstr.length >= 4 ? yearstr : '0000'.substr(0, 4 - yearstr.length) + yearstr;

	if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (yearstr + "").substr(4 - RegExp.$1.length));
	for (let k in o)
		if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
	return fmt;
};



// function open1(){
// 	alert(11);
// }


